using System;
using System.Collections.Generic;
using System.Text;

using SD.LLBLGen.Pro.ORMSupportClasses;
using DatabaseAdapter;
using DatabaseGeneric;
using DatabaseGeneric.FactoryClasses;
using DatabaseGeneric.EntityClasses;
using DatabaseGeneric.RelationClasses;
using DatabaseGeneric.HelperClasses;

namespace Services
{
    public class LoginLogout : Interfaces.ILoginLogout
    {
        public EntityCollection<LoginLogoutEntity> FetchCollection()
        {
            EntityCollection<LoginLogoutEntity> collectionLoginLogout = new EntityCollection<LoginLogoutEntity>();
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.FetchEntityCollection(collectionLoginLogout, null);
            }
            return collectionLoginLogout;
        }

        public LoginLogoutEntity FetchEntity(LoginLogoutEntity currentEntityLoginLogout)
        {
            LoginLogoutEntity entityLoginLogout = new LoginLogoutEntity(currentEntityLoginLogout.Username);
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.FetchEntity(entityLoginLogout);
            }
            return entityLoginLogout;
        }

        public int SaveCollection(EntityCollection<LoginLogoutEntity> currentCollectionLoginLogout)
        {
            int cntSave = 0;
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                cntSave = adapter.SaveEntityCollection(currentCollectionLoginLogout);
            }
            return cntSave;
        }

        public bool SaveEntity(LoginLogoutEntity currentEntityLoginLogout)
        {
            bool isSave = false;
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                isSave = adapter.SaveEntity(currentEntityLoginLogout);
            }
            return isSave;
        }

        public int DeleteCollection(EntityCollection<LoginLogoutEntity> currentCollectionLoginLogout)
        {
            int cntDelete = 0;
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                adapter.DeleteEntityCollection(currentCollectionLoginLogout);
            }
            return cntDelete;
        }

        public bool DeleteEntity(LoginLogoutEntity currentEntityLoginLogout)
        {
            bool isDelete = false;
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                isDelete = adapter.DeleteEntity(currentEntityLoginLogout);
            }
            return isDelete;
        }

        public System.Data.DataTable LoginByUsername(string username)
        {
            System.Data.DataTable dtUsername = new System.Data.DataTable();
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                dtUsername = RetrievalProcedures.LoginByUsername(username, adapter);
            }
            return dtUsername;
        }

        public System.Data.DataTable LoginByPassword(string username)
        {
            System.Data.DataTable dtPassword = new System.Data.DataTable();
            using (DataAccessAdapter adapter = new DataAccessAdapter())
            {
                dtPassword = RetrievalProcedures.LoginByPassword(username, adapter);
            }
            return dtPassword;
        }
    }
}
